package com.bjesc_b2c.app.appraiset.widget.popupwindow;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.bjesc_b2c.app.appraiset.R;
import com.bjesc_b2c.app.appraiset.adapter.SharepopAdapter;
import com.bjesc_b2c.app.appraiset.bean.ItemViewBean;
import com.bjesc_b2c.app.appraiset.widget.BasePopupWindow;
import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

import app.pinggushi.bjesc.com.baserecyclerview.adapter.MultiItemTypeAdapter;


/**
 * Created by yidong on 2017/9/8.
 */

public class ShareCarPop extends BasePopupWindow implements MultiItemTypeAdapter.OnItemClickListener {
    private RecyclerView recyclerView;
    private GridLayoutManager manager;
    private SharepopAdapter adapter;
    private Context context;
    private List<ItemViewBean> list;
    public static String WECHAT = "Wechat";
    public static String WECHAT_MOMENTS ="WechatMoments";
    public static String QQ = "QQ";
    public static String QZONE = "QZone";
    public static String MORE_IMAGE = "More_Image";
    private EditText editText;
    private ImageView imageView;

    private shareType share;
    private String[] titles = {"微信朋友", "朋友圈", "QQ", "QQ空间", "多图"};
    private int[] resID = {R.drawable.share_to_wxfriend, R.drawable.share_to_wxcircle,
            R.drawable.share_to_qq,  R.drawable.share_to_qzone,  R.drawable.socialize_share_nine_photo};

    public ShareCarPop(Context context, shareType share) {
        super(context, null);
        this.context = context;
        this.share = share;
        list = new ArrayList<>();
        for (int i = 0; i < titles.length; i++) {
            ItemViewBean bean = new ItemViewBean(titles[i], resID[i]);
            list.add(bean);
        }
        adapter = new SharepopAdapter(context, R.layout.socialize_share_menu_item, list);
        manager = new GridLayoutManager(context, 4);
        recyclerView.setLayoutManager(manager);
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(this);
    }
    public void setTitles(String url,String title){
        Glide.with(context).load(url).into(imageView);
        editText.setText(title);
        editText.setSelection(title.length());
    }
    @Override
    protected void initViews() {
        view = inflater.inflate(R.layout.pop_share_layout, null);
        recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
        editText = (EditText) view.findViewById(R.id.ed_title);
        imageView = (ImageView) view.findViewById(R.id.share_image);
        view.findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

    @Override
    protected int setRootViewId() {
        return R.id.lin_root;
    }

    @Override
    public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {

        if (share == null){
            return;
        }
        switch (position) {
            case 0:
                share.shareType(WECHAT,editText.getText().toString());
                break;
            case 1:
                share.shareType(WECHAT_MOMENTS,editText.getText().toString());
                break;
            case 2:
                share.shareType(QQ,editText.getText().toString());
                break;
            case 3:
                share.shareType(QZONE,editText.getText().toString());
                break;
            case 4:
                share.shareType(MORE_IMAGE,editText.getText().toString());
                break;

        }
    }

    @Override
    public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
        return false;
    }

    public interface shareType {
        void shareType(String typeId,String title);
    }
}
